<?php
$iMission = (@$iMission ? $iMission : $_REQUEST['iMission']);

$oJobs = JobHandler::getJobs();
$oMissions = $oJobs[$_SESSION['iJobID']]->getMissions();
$oMission = $oMissions[$iMission];

if (JobHandler::canDo('mission', 'read') && is_object($oMission)) {
	$bShowFinishTime = (@$bShowFinishTime ? $bShowFinishTime : (bool)@$_REQUEST['bShowFinishTime']);
	$bShowTotalwork = (@$bShowTotalwork ? $bShowTotalwork : (bool)@$_REQUEST['bShowTotalwork']);
	
	if (@$_SESSION['oJobSettings'][$_SESSION['iJobID']]['showchanger'] && !in_array($_SESSION['oJobSettings'][$_SESSION['iJobID']]['showchanger'], $oMission->iUsers))
	{
		return;
	}
	
	$oUsers = UserHandler::getUsers();
	$sMissionStatus = MissionHandler::getStatuses();
	$oJobConfig = $oJobs[$_SESSION['iJobID']]->getConfig();
	$iChangers = JobHandler::getUsersWithAccess('mission', 'write');;
	?>
		<td class="listentity center" nowrap>
			<a name="mission_<?php print $oMission->iID ?>"></a>
			<table class="boxborder" cellspacing="0" id="disabled_note_<?php print $oMission->iID ?>" style="display: none; position: absolute; margin: 24px 0px 0px 0px;">
				<tr>
					<td class="note small right" colspan="3">[ <a href="javascript: elfHide('note_<?php print $oMission->iID ?>');">X</a> ]</td>
				</tr>
			</table>
	<?php
	if (JobHandler::canDo('mission', 'write'))
	{
		if (@$oJobConfig['bUseWork'])
		{
			?>
			<a href="javascript: showBox('time-add', 'sView=job-view&iJob=<?php print $_SESSION['iJobID'] ?>&iMissionID=<?php print $oMission->iID ?>');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/time.png" alt="Skrá vinnu á verk" border="0"></a>
			<?php
		}
	}
	if ($oMission->iNoteCount == 0) {
		if (JobHandler::canDo('mission', 'write')) {
			?>
			<a href="javascript: showBox('note-add', 'iMissionID=<?php print $oMission->iID ?>');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/note-add.png" alt="Bæta við glósu" border="0"></a>
			<?php
		}
		else {
			print '&nbsp;';
		}
	}
	else
	{
		print '<a href="javascript: toggleNote('.$oMission->iID.');"><img src="images/'.$_SESSION['oUserVars']['images'].'/note.png" alt="Skoða glósu" border="0"></a> ';
	}
	if (@$oJobConfig['bShowReminder'])
	{
		?>
		<a href="javascript: showBox('mission-rush', 'iMissionID=<?php print $oMission->iID ?>');"><img src="images/<?php print $_SESSION['oUserVars']['images'] ?>/rush.png" border="0"></a>
		<?php
	}
	?>
		</td>
		<td class="missionstatus<?php print $oMission->iStatus ?>" nowrap>
			<a href="javascript: showBox('mission-show', 'iMissionID=<?php print $oMission->iID ?>');"><?php print htmlspecialchars($oMission->sTodo, ENT_COMPAT, 'ISO-8859-15') ?></a>
	<?php
	if ($oMission->iFileCount > 0) {
		$iMissionFiles = MissionHandler::getFiles($oMission->iID);
		$oFiles = JobHandler::getFiles($_SESSION['iJobID']);
		$bFirst = true;
		print '&nbsp;(';
		foreach ($iMissionFiles as $iThisFile) {
			if (!$bFirst) {
				print ', ';
			}
			print '<a href="index.php?sAction=job-filedownload&sFile='.urlencode($oFiles[$iThisFile]->sFilename).'&sView=job-view">';
			print '<img src="images/'.$_SESSION['oUserVars']['images'].'/file.png" border="0"> ';
			print ($oFiles[$iThisFile]->sDescription ? $oFiles[$iThisFile]->sDescription : $oFiles[$iThisFile]->sFilename);
			print '</a>';
			$bFirst = false;
		}
		print ')';
	}
	?>
		</td>
		<td class="missionstatus<?php print $oMission->iStatus ?> small" nowrap>
	<?php
	if (JobHandler::canDo('mission', 'write'))
	{
		print '<a href="javascript: getPiece(\'mission-show_single\', \'sAction=mission-changestatus&iStatus=0&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-white.png" border="0"></a> ';
		print '<a href="javascript: getPiece(\'mission-show_single\', \'sAction=mission-changestatus&iStatus=2&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-green.png" border="0"></a> ';
		print '<a href="javascript: getPiece(\'mission-show_single\', \'sAction=mission-changestatus&iStatus=5&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-blue.png" border="0"></a> ';
		print '<a href="javascript: hideNote('.$oMission->iID.'); getPiece(\'mission-show_single\', \'sAction=mission-changestatus&iStatus=3&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-gray.png" border="0"></a> ';
	}
	print $sMissionStatus[$oMission->iStatus]['caption'];
	?>
		</td>
	<?php
	if ($oJobs[$_SESSION['iJobID']]->sUrgencies[$oMission->iUrgency]) {
		print '<td class="listentity small center" nowrap>';
		if (JobHandler::canDo('mission', 'write')) {
			if ($oMission->iUrgency  != count($oJobs[$_SESSION['iJobID']]->sUrgencies) - 1) {
				print '<a href="javascript: getPiece(\'mission-show_single\', \'sAction=mission-changeurgency&iUrgency='.($oMission->iUrgency + 1).'&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-down.png" border="0"></a> ';
			}
		}
		print $oJobs[$_SESSION['iJobID']]->sUrgencies[$oMission->iUrgency];
		if (JobHandler::canDo('mission', 'write')) {
			if ($oMission->iUrgency > 0) {
				print ' <a href="javascript: getPiece(\'mission-show_single\', \'sAction=mission-changeurgency&iUrgency='.($oMission->iUrgency - 1).'&iMission='.$oMission->iID.'&bShowFinishTime='.$bShowFinishTime.'&bShowTotalwork='.$bShowTotalwork.'\', \'holder_job_view_mission_'.$oMission->iID.'\');"><img src="images/custom/dot-up.png" border="0"></a>';
			}
		}
		print '</td>';
	}
	else {
		print '<td class="listentity_inactive small center" nowrap>[ Óþekkt ]</td>';
	}
	if ($bShowTotalwork) {
		print '<td class="listentity small center">'.calcHours($oMission->iTotalwork).'</td>';
	}
	if (count($iChangers) > 1) {
		print '<td class="listentity small center" nowrap>';
		for ($i = 0; $i < count($oMission->iUsers); $i++) {
			if ($i > 0) {
				print ', ';
			}
			print '<a href="index.php?sView=user-view&iUser='.$oMission->iUsers[$i].'">'.$oUsers[$oMission->iUsers[$i]]->sUser.'</a>';
		}
		print '</td>';
	}
	if ($bShowFinishTime) {
		print '<td class="listentity small center" nowrap>';
		if (!$oMission->iFinishTime)
		{
			print '&nbsp;';
		}
		else if ($oMission->iFinishTime < thisSecond())
		{
			print '<span class="error">'.coolDate($oMission->iFinishTime).'</span>';
		}
		else
		{
			print coolDate($oMission->iFinishTime);
		}
		print '</td>';
	}
}

?>
